package webmarket.common;

import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import webmarket.controller.transferobjects.JQueryDataTableParamModel;
import webmarket.controller.transferobjects.UserTO;

@XmlRootElement
@XmlAccessorType(XmlAccessType.NONE)
public class DatatableResponse<T extends XmlBase> extends XmlBase {
	private static final long serialVersionUID = 2624397584333736229L;
	private String sEcho;
	private String iTotalRecords;
	private String iTotalDisplayRecords;
	private List<T> aaData;
	
	@Override
	protected void addAttitionalClasses(List<Class<? extends XmlBase>> classList) {
		classList.add(UserTO.class);
	}

	/**
	 * do not call this constructor! It is only for JAXB
	 */
	public DatatableResponse() {
		//TODO: do not call this constructor! It is only for JAXB
	}

	public DatatableResponse(JQueryDataTableParamModel param) {
		setsEcho(param.sEcho);
	}

	public void setData(List<T> aaData, int iTotalRecords, int iTotalDisplayRecords) {
		this.setAaData(aaData);
		this.setiTotalDisplayRecords("" + iTotalDisplayRecords);
		this.setiTotalRecords("" + iTotalRecords);
	}

	/**
	 * @return the sEcho
	 */
	@XmlElement
	public String getsEcho() {
		return sEcho;
	}

	/**
	 * @return the iTotalRecords
	 */
	@XmlElement
	public String getiTotalRecords() {
		return iTotalRecords;
	}

	/**
	 * @return the iTotalDisplayRecords
	 */
	@XmlElement
	public String getiTotalDisplayRecords() {
		return iTotalDisplayRecords;
	}

	/**
	 * @return the aaData
	 */
	@XmlElement(name="listElement")
	@XmlElementWrapper
	public List<T> getAaData() {
		return aaData;
	}
	
	@XmlElement
	public int getListCount(){
		return aaData.size();
	}

	

	/**
	 * @param sEcho
	 *            the sEcho to set
	 */
	public void setsEcho(String sEcho) {
		this.sEcho = sEcho;
	}

	/**
	 * @param iTotalRecords
	 *            the iTotalRecords to set
	 */
	public void setiTotalRecords(String iTotalRecords) {
		this.iTotalRecords = iTotalRecords;
	}

	/**
	 * @param iTotalDisplayRecords
	 *            the iTotalDisplayRecords to set
	 */
	public void setiTotalDisplayRecords(String iTotalDisplayRecords) {
		this.iTotalDisplayRecords = iTotalDisplayRecords;
	}

	/**
	 * @param aaData
	 *            the aaData to set
	 */
	public void setAaData(List<T> aaData) {
		this.aaData = aaData;
	}
}
